package dji.ux.ext.setting.battery;

import androidx.annotation.NonNull;

import dji.keysdk.DJIKey;
import dji.keysdk.FlightControllerKey;
import dji.thirdparty.io.reactivex.Completable;
import dji.thirdparty.io.reactivex.Flowable;
import dji.ux.beta.base.DJISDKModel;
import dji.ux.beta.base.SchedulerProviderInterface;
import dji.ux.beta.base.WidgetModel;
import dji.ux.beta.base.uxsdkkeys.ObservableInMemoryKeyedStore;
import dji.ux.beta.util.DataProcessor;

public class SmartReturnModel extends WidgetModel {
    private SchedulerProviderInterface schedulerProvider;
    private final DataProcessor<Boolean> smartReturnEnabledProcessor;

    public SmartReturnModel(@NonNull DJISDKModel djiSdkModel,
                          @NonNull ObservableInMemoryKeyedStore keyedStore,
                          @NonNull SchedulerProviderInterface scheduletProviderInterface) {
        super(djiSdkModel, keyedStore);
        this.schedulerProvider = scheduletProviderInterface;
        smartReturnEnabledProcessor = DataProcessor.create(false);
    }

    public Flowable<Boolean> getSmartReturnEnabled() {
        return smartReturnEnabledProcessor.toFlowable();
    }

    public Completable setEnable(boolean isChecked) {
        DJIKey smartReturnEnabledKey = FlightControllerKey.create(FlightControllerKey.SMART_RETURN_TO_HOME_ENABLED);
        return djiSdkModel.setValue(smartReturnEnabledKey, isChecked).subscribeOn(schedulerProvider.io());
    }

    @Override
    protected void inSetup() {
        FlightControllerKey smartReturnEnabledKey =
                FlightControllerKey.create(FlightControllerKey.SMART_RETURN_TO_HOME_ENABLED);
        bindDataProcessor(smartReturnEnabledKey, smartReturnEnabledProcessor);
    }

    @Override
    protected void inCleanup() {

    }

    @Override
    protected void updateStates() {

    }
}
